package ru.spbau.bytecode.projectobserver;

import static org.junit.Assert.assertTrue;

import java.io.File;

import org.junit.Before;
import org.junit.Test;

import ru.spbau.bytecode.graph.CompositeVertex;
import ru.spbau.bytecode.graph.Edge;
import ru.spbau.bytecode.graph.Graph;
import ru.spbau.bytecode.graph.GraphException;

public class PackagesObserverTest {
	
	private final Graph expectedGraph = new Graph();

	@Before
	public void setUp() {
		CompositeVertex v1 = new CompositeVertex("ru.spbau.bytecode");
		CompositeVertex v2 = new CompositeVertex("ru.spbau.bytecode.graph");
		CompositeVertex v3 = new CompositeVertex("ru.spbau.bytecode.gui");
		CompositeVertex v4 = new CompositeVertex("ru.spbau.bytecode.info");
		CompositeVertex v5 = new CompositeVertex("ru.spbau.bytecode.projectobserver");
		CompositeVertex v6 = new CompositeVertex("ru.spbau.bytecode.reader");
		
		Edge e1 = new Edge(v1, v3);
		Edge e2 = new Edge(v1, v5);
		Edge e3 = new Edge(v3, v2);
		Edge e4 = new Edge(v5, v2);
		Edge e5 = new Edge(v5, v6);
		Edge e6 = new Edge(v6, v4);
		
		expectedGraph.addVertex(v1);
		expectedGraph.addVertex(v2);
		expectedGraph.addVertex(v3);
		expectedGraph.addVertex(v4);
		expectedGraph.addVertex(v5);
		expectedGraph.addVertex(v6);
		
		expectedGraph.addEdge(e1);
		expectedGraph.addEdge(e2);
		expectedGraph.addEdge(e3);
		expectedGraph.addEdge(e4);
		expectedGraph.addEdge(e5);
		expectedGraph.addEdge(e6);
	}
	
	@Test
	public void testBuildGraph() throws GraphException {
		PackagesObserver observer = new PackagesObserver();
		Graph resultGraph = observer.buildGraph(
				new File("resources/testData/testForPackagesObserver"));
		GraphComparator cmp = new GraphComparator();
		assertTrue(cmp.equals(expectedGraph, resultGraph));
	}
}
